function _bindInputChange(newVal, oldVal, queryPageUrl, index){
    var valueInput = $("input[_idcard='value_"+index+"']")[0];
    var displayInput = $("input[_idcard='display_"+index+"']")[0];
    if(typeof(oldVal) == "undefined"){
        if(valueInput.getAttribute("valueField") == valueInput.getAttribute("displayField")){
            displayInput.value = newVal;
            return;
        }
        var data = {};
        //框架后台查询都是基于表字段，此处将大写字母转下划线加小写拼接
        var field = valueInput.getAttribute('valueField').replace(/[A-Z]/g,function(a,b){
            return "_"+a.toLocaleLowerCase();
        });
        data[field] = newVal;
        if(data[field] != null){
            $.ajax({
                type: "POST",
                url: queryPageUrl,
                data: data,
                success: function(r){
                    if(r.code=='0' && r.data.data.length == 1){
                        displayInput.value = r.data.data[0][valueInput.getAttribute('displayField')];
                    }else{
                        throw "服务器返回错误!或者目标查询字段["+valueInput.getAttribute("valueField")+"]有多条数据!查询地址:"+queryPageUrl;
                    }
                }
            });
        }
    }else if(typeof(newVal) == "undefined"){
        displayInput.value = "";
    }
}
function _bindInputBtnYes(index, layero){
    var currentLayer = this;
    var iframeWin = window[layero.find('iframe')[0]['name']];
    var data;
    if(typeof(currentLayer.callback) != "undefined" && currentLayer.callback != ""){
        data = eval("iframeWin."+currentLayer.callback+"();");
    }else{
        data = iframeWin.getSelectedRowData();
    }

    if(typeof(data[currentLayer.valueField]) != "undefined"){
        $("input[_idCard=display_"+currentLayer.bindInputIndex+"]")[0].value=data[currentLayer.displayField];
        if(currentLayer.vModelFullPath){
            $("input[_idCard=value_"+currentLayer.bindInputIndex+"]")[0].value=data[currentLayer.valueField];
            eval(currentLayer.vModelFullPath+"='"+data[currentLayer.valueField]+"';");
        }else{
            $("input[_idCard=value_"+currentLayer.bindInputIndex+"]")[0].value=data[currentLayer.valueField];
        }
        layer.close(index);
    }
}
function _bindInputBtnSuccess(layero, index){
    var body = layer.getChildFrame('body', index);
    body.find('.grid-btn').remove();
}
function bindInputFormOpen(){
    var input = $("input");
    var defaultOption = {
        type : 2,
        title : '选择窗口',
        area : ['100%','100%'],
        shadeClose:true,
        move: false,
        content : ""
    };
    $.each(input,function(index,valueInput){
        var attr = valueInput.getAttribute('inputfromopen');
        if (attr != null) {
            valueInput = $(valueInput);
            if(valueInput.attr("v-model")){
                throw "控件申明了v-model，必须在new Vue({...});初始化之后再执行本方法!因为$watch监听需要vue支持";
            }
            var option = valueInput.attr('layerOption');
            var valueField = valueInput.attr("valueField");
            var displayField = valueInput.attr("displayField");
            displayField = !displayField || displayField=='' ? valueField : displayField;
            var callback = valueInput.attr("selectCallbackFn");
            var vModelFullPath = valueInput.attr("vModelFullPath");
            var queryPageUrl = valueInput.attr("queryPageUrl");
            queryPageUrl = queryPageUrl.replace("{spaceId}", getCookie("user_space_id"));
            valueInput.removeAttr("layerOption")
                .removeAttr("selectCallbackFn")
                .removeAttr("queryPageUrl")
                .removeAttr("inputfromopen");
            var displayInput = valueInput.clone()
                .removeAttr("valueField")
                .removeAttr("displayField")
                .attr("readonly","true")
                .removeAttr("v-model")
                .attr("name","display_"+valueInput.attr("name"))
                .attr("id","display_"+valueInput.attr("id"))
                .attr("_idCard", "display_"+index);
            valueInput.after(displayInput);
            valueInput
                .css("display","none")
                .attr("_idCard", "value_"+index);
            defaultOption.displayField = displayField;
            defaultOption.valueField = valueField;
            defaultOption.callback = callback;
            defaultOption.bindInputIndex = index;

            option = eval("("+option+")");
            $.each(option, function(key,value){
                defaultOption[key] = value;
            })
            defaultOption.btn = ['确定'];
            defaultOption.yes = '_bindInputBtnYes';
            defaultOption.success = '_bindInputBtnSuccess';

            if(vModelFullPath){//如果有配置vModelFullPath，需要监听属性变换，使用vue支持的特定的方式
                defaultOption.vModelFullPath = vModelFullPath;//传递给layer，用于在yes按钮确定后赋值，v-model一旦绑定数据，不能通过传统方式赋值
                var vueObjName = vModelFullPath.substring(0,vModelFullPath.indexOf("."));
                var dataPath = vModelFullPath.substring(vModelFullPath.indexOf(".")+1,vModelFullPath.length);
                //监听值变化，为了巧妙的增加额外参数，重新定义了function 并增加了第三个参数，巧妙的给vue回调的函数传过去我们需要的参数
                eval(vueObjName+".$watch('"+dataPath+"', function(a,b,c='"+queryPageUrl+"',d="+index+"){return _bindInputChange(a,b,c,d);})");
            }

            var layerOption = JSON.stringify(defaultOption);
            layerOption = layerOption.replace("\"_bindInputBtnYes\"",'_bindInputBtnYes');
            layerOption = layerOption.replace("\"_bindInputBtnSuccess\"",'_bindInputBtnSuccess');
            displayInput.attr('onclick', "layer.open("+layerOption+");");
        }
    });
}